package com.chenchao.net;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/25 20:40
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.net.Test09A.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 组播接收方
 */
public class Test09A {
    public static void main(String[] args) throws IOException {
        /*创建特殊码头*/
        MulticastSocket multicastSocket = new MulticastSocket(10000);
        /*合并到码头集合*/
        InetAddress address = InetAddress.getByName("224.0.1.0");
        multicastSocket.joinGroup(address);
        /*创建集装箱*/
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);
        /*卸货*/
        multicastSocket.receive(dp);
        System.out.println(new String(dp.getData(), 0, dp.getLength()));
        /*关码头*/
        multicastSocket.close();
    }
}
